﻿using AutoMapper;
using FarmSmartSleep.Common.Domain.RaiseManagement;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.RaiseCommands
{
    public class EliminateTypeHandler : IRequestHandler<EliminateTypeCommand, Result>
    {
        public IBaseRepository<Culled> culledRepository;
        public IMapper mapper;

        public EliminateTypeHandler(IBaseRepository<Culled> culledRepository, IMapper mapper)
        {
            this.culledRepository = culledRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 淘汰原因下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<Result> Handle(EliminateTypeCommand request, CancellationToken cancellationToken)
        {
            Result result = new Result();
            result.Code = 1;
            result.Messege = "成功";
            var res = culledRepository.GetAll().ToList();
            List<EliminateTypeListCommand> lists = new List<EliminateTypeListCommand>();
            foreach (var item in res)
            {
                var sf = mapper.Map<EliminateTypeListCommand>(item);
                lists.Add(sf);
            }
            result.Data = lists;
            return Task.FromResult(result);
        }
    }
}
